angular.module('myApp', ['infinite-scroll']);

function cuxiao($scope, $http) {
	var gid = readData(localStorage.guideId);
	var aid = readData(localStorage.promotionId);
	var ruleType = readData(localStorage.ruleType);
	$scope.Name = readData(localStorage.promotionName);
	var allgoodsUrl = getUrl("82promotionProductList");
	var headerAll = getHeader();
	var paramsAll;
	//默认加载第一页，初始值0
	$scope.pages = 0;
	$scope.totalpage = 1;
	$scope.goodsAll = [];
	//商品
	$scope.all_products = function() {
			if ($scope.pages < $scope.totalpage) {
				paramsAll = 'userId=' + gid + '&activityId=' + aid + '&indexpage=' + $scope.pages + '&pageSize=6&ruleType=' + ruleType;
				$scope.pages = $scope.pages + 1;
				$http({
					method: 'POST',
					url: allgoodsUrl,
					headers: headerAll,
					timeout: 10000,
					//cache: true,
					data: paramsAll
				}).success(function(data, status, headers, config) {
					if (data.obj) {
						console.log(JSON.stringify(data.obj))
						var goodsList = data.obj.list;
						for (var i = 0; i < goodsList.length; i++) {
							$scope.goodsAll.push(goodsList[i]);
						}
						for (var i = 0; i < $scope.goodsAll.length; i++) {
							if (!$scope.goodsAll[i].picture) {
								$scope.goodsAll[i].picture = '../../image/shopping/middle.png';
							}
						}
						$scope.totalpage = data.obj.totalpage;
					} else {
						$scope.goodsAll = [];
						$scope.pages = $scope.pages - 1;
					};
				}).error(function() {
					$scope.pages = $scope.pages - 1;
					console.log('促销活动出错');
				});
			}
		}
		//获取商品ID，打开商品详情页
	$scope.detail = function(id) {
		localStorage.goodsId = writeData(id);
		mui.openWindow({
			url: 'productDetail.html',
			id: 'productDetail.html'
		});
	}
}